package hsh.systemcalls;


import hsh.drivers.DeviceDriver;
import hsh.exceptions.DeviceDriverNotFoundException;
import hsh.exceptions.DeviceOccupiedException;
import hshsm.managers.DeviceManager;

public class SystemCalls {

	private static SystemCalls instance;
	private DeviceDriver driver;
	private DeviceManager deviceManager;
	
	public enum Call{
		ON
	}
	
	private SystemCalls(){	
		
	}
	
	
	public static SystemCalls getInstance(){
		if( instance == null)
			 instance = new SystemCalls();
		
		return instance;
			
	}
	
	public void on(String nameDevice) throws DeviceDriverNotFoundException, DeviceOccupiedException{
		
		driver = deviceManager.searchDeviceDriver(nameDevice);
		if(!driver.isBusy()){
			driver.getDevice();//block the device 
			driver.onDevice();
		}
		
		throw new DeviceOccupiedException();
	}
	
	
	
	public void off(){
		driver.offDevice();
	}
	
	
	public void release(){
		driver.releaseDevice();
	}
	
	public void setDriver(DeviceDriver driver){
		this.driver = driver;
	}
	
}
